package oracle.apps.financials.collection.activity;

import oracle.apps.financials.collection.dao.DatabaseHelper;
import oracle.apps.financials.collection.fragment.BaseGraphFragment;
import oracle.apps.financials.collection.fragment.MenuBarFragment;
import oracle.apps.financials.collection.po.Customer;
import oracle.apps.financials.collection.widget.ProgressBar;
import android.app.FragmentManager;
import android.app.FragmentTransaction;
import android.app.ListActivity;
import android.os.Bundle;
import android.os.Handler;

import com.cyrilmottier.android.greendroid.R;
import com.j256.ormlite.android.apptools.OpenHelperManager;

public abstract class BaseListActivity extends ListActivity {

	public static final String TAG = BaseListActivity.class.getSimpleName();

	protected BaseGraphFragment graphFragment;
	protected MenuBarFragment menuFragment;
	protected Customer customer;
	private DatabaseHelper databaseHelper = null;
	protected ProgressBar mProgressBar;
	protected Handler mHandler;

	public BaseListActivity() {
		super();
	}
	
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);				
	}

	public void intitMenuBarAndGraphFragment(Customer customer) {

		if (menuFragment == null) {

			FragmentManager fragmentManager = getFragmentManager();
			FragmentTransaction fragmentTransaction = fragmentManager.beginTransaction();
			menuFragment = new MenuBarFragment();
			fragmentTransaction.add(R.id.menu_bar, menuFragment);

			graphFragment = new BaseGraphFragment(customer);
			fragmentTransaction.add(R.id.graph_area, graphFragment);
			fragmentTransaction.commit();
		}

	}

	@Override
	protected void onDestroy() {
		super.onDestroy();

		/*
		 * You'll need this in your class to release the helper when done.
		 */
		if (databaseHelper != null) {
			OpenHelperManager.releaseHelper();
			databaseHelper = null;
		}
	}

	/**
	 * You'll need this in your class to get the helper from the manager once
	 * per class.
	 */
	public DatabaseHelper getDatabaseHelper() {
		if (databaseHelper == null) {
			databaseHelper = OpenHelperManager.getHelper(this, DatabaseHelper.class);
		}
		return databaseHelper;
	}
	
	
	public void setHandler(Handler mHandler) {
		this.mHandler = mHandler;
	}
 

}
